//获取应用实例 
var app = getApp()
Page({
  data: {
    teamList: [],
  },
  onShow:function(){
    
  },
  onReady:function(){
   
  },
  onLoad: function () {
    this.getBannerMsg();
  },

  //获取推荐人信息
  getBannerMsg() {
    var that = this;
    wx.request({
      url: app.globalData.api + '/index.php/wap/Banner/getMsg',
      data:
      {
        id: 3,
      },
      headers: {
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 1) {
          res.data.data.bannerMsg.img = app.globalData.imgUrl + res.data.data.bannerMsg.img
          that.setData({
            bannerImg: res.data.data.bannerMsg.img,
          })
          
        } else {
          wx.showToast({
            title: '' + res.data.msg,
            icon: 'none',
            duration: 1000
          })
        }
        that.getRMsg();
      }, fail: function () {

      }
    });
  },

  //获取推荐人信息
  getRMsg() {
    var that = this;
    wx.request({
      url: app.globalData.api + '/index.php/wap/User/getRMsg',
      data:
      {
        token: app.globalData.token,
      },
      headers: {
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 1) {
          res.data.data.referrerMsg.avatar = app.globalData.imgUrl + res.data.data.referrerMsg.avatar
          that.setData({
            teamList:res.data.data.referrerMsg,
            defaultAvatar:app.globalData.defaultAvatar
          })
        } else {
          wx.showToast({
            title: '' + res.data.msg,
            icon: 'none',
            duration: 1000
          })
        }

      }, fail: function () {

      }
    });
  },
  onReady: function () {
    wx.setNavigationBarTitle({
      title: '我的推荐人'
    })
  },

  /**
 * 点击tab切换
 */
  swichNav: function (e) {

    var that = this;
    // console.log(e)

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  /**
     * 滑动切换tab
     */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },

  copyText:function(e){
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
})
